package org.ybxb.demo;

import java.util.Collections;

import org.junit.jupiter.api.Test;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

/**
 * @ProjectName: apaas-demo
 * @PackageName: com.ctsi.ssdc
 * @Description:
 * @Author: hy.bai
 * @Date: 2024-02-06 10:41
 */
public class MybatisPlusGeneratorDemo {

  @Test
  public void generator() {
    String url = "jdbc:mysql://127.0.0.1:3308/ybxb";
    String username = "root";
    String password = "root";
    FastAutoGenerator.create(url, username, password).globalConfig(builder -> {
      builder.author("ybxb") // 设置作者
          .enableSpringdoc() // 开启Springdoc模式
          .outputDir("D:\\works\\IDEA\\IdeaProjects\\maven-boot-demo\\src\\main\\java"); // 指定输出目录
    }).packageConfig(builder -> {
      builder.parent("org.ybxb.demo") // 设置父包名
          .moduleName("user") // 设置父包模块名
          .pathInfo(Collections.singletonMap(OutputFile.xml,
              "D:\\works\\IDEA\\IdeaProjects\\maven-boot-demo\\src\\main\\resources\\mappers")); // 设置mapperXml生成路径
    }).strategyConfig(builder -> {
      builder.addInclude("t_user") // 设置需要生成的表名
          .addTablePrefix("t_", "c_"); // 设置过滤表前缀
    }).templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
        .execute();
  }

}
